|
RAIS
3.2
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Text; 00004 using System.Net; 00005 using System.IO; 00006 using System.Xml; 00007 using System.Collections; 00008 using System.Diagnostics; 00009 using System.Data; 00010 00011 namespace IcSRS_Import 00012 { 00016 public class IcSRS_Import 00017 { 00018 private HttpWebRequest webRequest; 00019 private HttpWebResponse webResponse; 00020 private string type; 00021 private string search; 00022 private string loginIcSRS; 00023 private string passwordIcSRS; 00024 00025 public DataTable getSearchResult(string search, string type, string login, string password) 00026 { 00027 /* This public method returns a DataTable containing the 00028 * respective search result. 00029 */ 00030 00031 this.search = search; 00032 this.type = type; 00033 this.loginIcSRS = login; 00034 this.passwordIcSRS = password; 00035 switch (type) 00036 { 00037 case "Associated Equipment": 00038 return this.getDevices(); 00039 case "Source": 00040 return this.getSources(); 00041 case "Manufacturer": 00042 return this.getManufacturer(); 00043 default: 00044 return new DataTable(); 00045 } 00046 } 00047 00048 #region CURRENTLY NOT IN USE 00049 00050 public DataTable getDeviceDetails(string did) 00051 { 00052 DataTable details = new DataTable(); 00053 details.Columns.Add("Attribute"); 00054 details.Columns.Add("Value"); 00055 00056 try 00057 { 00058 XmlDocument doc = new XmlDocument(); 00059 //doc.Load(getXmlStream("https://icsrs.iaea.org/rais_search.aspx?username=rais_user&pwd=X9zb2[8&schem=0&op=dd&did=" + did)); 00060 doc.Load(getXmlStream( 00061 string.Format("https://icsrs.iaea.org/rais_search.aspx?username={0}&pwd={1}&schem=0&op=dd&did=" 00062 , loginIcSRS 00063 , passwordIcSRS) 00064 + did)); 00065 DataRow row = details.NewRow(); 00066 foreach (XmlNode node in doc.DocumentElement.ChildNodes[0].ChildNodes) 00067 { 00068 row[0] = node.Name; 00069 row[1] = node.InnerText; 00070 } 00071 details.Rows.Add(row); 00072 } 00073 catch (Exception ex) 00074 { 00075 Debug.WriteLine(ex.ToString()); 00076 } 00077 return details; 00078 } 00079 00080 public DataTable getSourceDetails(string sid) 00081 { 00082 DataTable details = new DataTable(); 00083 details.Columns.Add("Attribute"); 00084 details.Columns.Add("Value"); 00085 00086 try 00087 { 00088 XmlDocument doc = new XmlDocument(); 00089 //doc.Load(getXmlStream("https://icsrs.iaea.org/rais_search.aspx?username=rais_user&pwd=X9zb2[8&schem=0&op=sd&sid=" + sid)); 00090 doc.Load(getXmlStream( 00091 string.Format("https://icsrs.iaea.org/rais_search.aspx?username={0}&pwd={1}&schem=0&op=sd&sid=" 00092 , loginIcSRS 00093 , passwordIcSRS) 00094 + sid)); 00095 DataRow row = details.NewRow(); 00096 foreach (XmlNode node in doc.DocumentElement.ChildNodes[0].ChildNodes) 00097 { 00098 row[0] = node.Name; 00099 row[1] = node.InnerText; 00100 } 00101 details.Rows.Add(row); 00102 } 00103 catch (Exception ex) 00104 { 00105 Debug.WriteLine(ex.ToString()); 00106 } 00107 return details; 00108 } 00109 00110 #endregion 00111 00112 #region PRIVATE HELPER METHODS 00113 00114 private DataTable getDevices() 00115 { 00116 // Create DataTable which has to be returned. 00117 DataTable devices = new DataTable(); 00118 try 00119 { 00120 // Load XML-Document from icsrs.iaea.org, using the getXmlStream Method. 00121 XmlDocument doc = new XmlDocument(); 00122 //doc.Load(this.getXmlStream("https://icsrs.iaea.org/rais_search.aspx?username=rais_user&pwd=X9zb2[8&qry=" + search + "&schem=0&op=ds&nstart=0&ncount=1000")); 00123 doc.Load(this.getXmlStream( 00124 string.Format("https://icsrs.iaea.org/rais_search.aspx?username={0}&pwd={1}&qry=" 00125 , loginIcSRS 00126 , passwordIcSRS) 00127 + search + "&schem=0&op=ds&nstart=0&ncount=1000")); 00128 00129 /* Create default column with type of boolean. 00130 * The checkboxes in the GridView are bound to this 00131 * column, which will be hidden by "Import.aspx.cs". 00132 */ 00133 devices.Columns.Add("Selected", typeof(bool)); 00134 00135 // Create default column which shows the current item index. 00136 devices.Columns.Add("#"); 00137 00138 // Parse Xml Nodes 00139 foreach (XmlNode node in doc.DocumentElement.ChildNodes) 00140 { 00141 foreach (XmlNode current in node.ChildNodes) 00142 { 00143 /* Check if the name of the current node is not already contained in 00144 * DataTable.Columns and if current nodes name not equals "final_CountId" 00145 * which should not be displayed in the search result grid view. 00146 */ 00147 if (!devices.Columns.Contains(current.Name) && !current.Name.Equals("final_CountId")) 00148 { 00149 devices.Columns.Add(current.Name); 00150 } 00151 } 00152 } 00153 00154 // Fill current DataTable with attributes 00155 fillTableData(doc, devices); 00156 } 00157 catch (Exception ex) 00158 { 00159 Debug.WriteLine("Error!\n " + ex.ToString()); 00160 } 00161 return devices; 00162 } 00163 00164 private DataTable getSources() 00165 { 00166 // Create DataTable which has to be returned. 00167 DataTable sources = new DataTable(); 00168 try 00169 { 00170 // Load XML-Document from icsrs.iaea.org, using the getXmlStream Method. 00171 XmlDocument doc = new XmlDocument(); 00172 //doc.Load(getXmlStream("https://icsrs.iaea.org/rais_search.aspx?username=rais_user&pwd=X9zb2[8&qry=" + search + "&nstart=1&ncount=1000&schem=0&op=s")); 00173 doc.Load(getXmlStream( 00174 string.Format("https://icsrs.iaea.org/rais_search.aspx?username={0}&pwd={1}&qry=" 00175 , loginIcSRS 00176 , passwordIcSRS) 00177 + search + "&nstart=1&ncount=1000&schem=0&op=s")); 00178 00179 /* Create default column with type of boolean. 00180 * The checkboxes in the GridView are bound to this 00181 * column, which will be hidden by "Import.aspx.cs". 00182 */ 00183 sources.Columns.Add("Selected", typeof(bool)); 00184 00185 // Create default column which shows the current item index. 00186 sources.Columns.Add("#"); 00187 00188 // Parse Xml Nodes 00189 foreach (XmlNode node in doc.DocumentElement.ChildNodes) 00190 { 00191 foreach (XmlNode current in node.ChildNodes) 00192 { 00193 /* Check if the name of the current node is not already contained in 00194 * DataTable.Columns and if current nodes name not equals "final_CountId" 00195 * which should not be displayed in the search result grid view. 00196 */ 00197 if (!sources.Columns.Contains(current.Name) && !current.Name.Equals("final_CountId")) 00198 { 00199 sources.Columns.Add(current.Name); 00200 } 00201 } 00202 } 00203 00204 // Fill current DataTable with attributes 00205 fillTableData(doc, sources); 00206 } 00207 catch (Exception ex) 00208 { 00209 Debug.WriteLine(ex.ToString()); 00210 } 00211 return sources; 00212 } 00213 00214 private DataTable getManufacturer() 00215 { 00216 // Create DataTable which has to be returned. 00217 DataTable manufacturer = new DataTable(); 00218 try 00219 { 00220 // Load XML-Document from icsrs.iaea.org, using the getXmlStream Method. 00221 XmlDocument doc = new XmlDocument(); 00222 //doc.Load(getXmlStream("https://icsrs.iaea.org/rais_search.aspx?username=rais_user&pwd=X9zb2[8&qry=" + search + "&nstart=1&ncount=1000&schem=0&op=ss")); 00223 doc.Load(getXmlStream( 00224 string.Format("https://icsrs.iaea.org/rais_search.aspx?username={0}&pwd={1}&qry=" 00225 , loginIcSRS 00226 , passwordIcSRS) 00227 + search + "&nstart=1&ncount=1000&schem=0&op=ss")); 00228 00229 /* Create default column with type of boolean. 00230 * The checkboxes in the GridView are bound to this 00231 * column, which will be hidden by "Import.aspx.cs". 00232 */ 00233 manufacturer.Columns.Add("Selected", typeof(bool)); 00234 00235 // Create default column which shows the current item index. 00236 manufacturer.Columns.Add("#"); 00237 00238 // Parse Xml Nodes 00239 foreach (XmlNode node in doc.DocumentElement.ChildNodes) 00240 { 00241 foreach (XmlNode current in node.ChildNodes) 00242 { 00243 /* Check if the name of the current node is not already contained in 00244 * DataTable.Columns and if current nodes name equals one of names below. 00245 */ 00246 if (!manufacturer.Columns.Contains(current.Name)) 00247 { 00248 if (current.Name.Equals("Company") || current.Name.Equals("Address1") || current.Name.Equals("Telephone1") || current.Name.Equals("Fax") || current.Name.Equals("E-Mail") || current.Name.Equals("Country")) 00249 manufacturer.Columns.Add(current.Name); 00250 } 00251 } 00252 } 00253 00254 // Fill current DataTable with attributes 00255 fillTableData(doc, manufacturer); 00256 } 00257 catch (Exception ex) 00258 { 00259 Debug.WriteLine(ex.ToString()); 00260 } 00261 return manufacturer; 00262 } 00263 00264 private Stream getXmlStream(string url) 00265 { 00266 // Creates a new HttpWebRequest and sets it's properties. 00267 webRequest = (HttpWebRequest)WebRequest.Create(url); 00268 webRequest.KeepAlive = false; 00269 webRequest.Method = "GET"; 00270 00271 // Create new HttpWebResponse and download the Response Stream. 00272 webResponse = (HttpWebResponse)webRequest.GetResponse(); 00273 return webResponse.GetResponseStream(); 00274 } 00275 00276 private void fillTableData(XmlDocument doc, DataTable dt) 00277 { 00278 // Parse Xml Nodes for inserting the returned values into the DataTable 00279 foreach (XmlNode node in doc.DocumentElement.ChildNodes) 00280 { 00281 // Create new DataRow 00282 DataRow row = dt.NewRow(); 00283 00284 // Set default values for Columns: "Selected" (row checked), and "#" (index of current row) 00285 row[0] = false; 00286 row[1] = dt.Rows.Count + 1; 00287 00288 // Set values for the current row 00289 foreach (XmlNode current in node.ChildNodes) 00290 { 00291 if (row.Table.Columns.Contains(current.Name)) 00292 row[current.Name] = current.InnerText; 00293 } 00294 00295 // Add DataRow to the DataTable 00296 dt.Rows.Add(row); 00297 } 00298 } 00299 00300 #endregion 00301 } 00302 }